package com.lntea.mybatisDemo.test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import com.lntea.mybatisDemo.domain.AccountSettleInfo;
import com.lntea.mybatisDemo.mapper.AccountSettleInfoBeanMapper;

public class AccountSettleInfoService {
	private SqlSessionFactory sqlSessionFactory;

	@Before
	public void beforeQuery() {
		String resource = "mybatis-config.xml";
		try {
			InputStream is = Resources.getResourceAsStream(resource);
			sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@Test
	//查询T+N结算数
	public void queryAccountSettleInfoTCount(){
		SqlSession session = sqlSessionFactory.openSession();
		try{
			AccountSettleInfoBeanMapper mapper = session.getMapper(AccountSettleInfoBeanMapper.class);
			
			AccountSettleInfo info = new AccountSettleInfo();
			info.setStartDate("2015-01-01");
			info.setEndDate("2015-08-10");
			info.setMerchantNo("102002858120033");
			Integer count = mapper.queryAccountSettleInfoTCount(info);
			System.out.println(count);
		} finally {
			session.close();
		}
	}
	
	@Test
	//查询T+N结算列表
	public void queryAccountSettleInfoTList() {
		SqlSession session = sqlSessionFactory.openSession();
		try{
			AccountSettleInfoBeanMapper mapper = session.getMapper(AccountSettleInfoBeanMapper.class);
			
			AccountSettleInfo info = new AccountSettleInfo();
			info.setStartDate("2015-01-01");
			info.setEndDate("2015-08-10");
			info.setMerchantNo("102002858120033");
			info.setPage(2);
			info.setRows(5);
			Integer count = mapper.queryAccountSettleInfoTCount(info);
			if(count > 0){
				info.getPager().setRowCount(count);
				List<AccountSettleInfo> list = mapper.queryAccountSettleInfoTList(info);
				for(AccountSettleInfo temp : list){
					System.out.println(temp.getSettleMoney());
				}
			}
		} finally {
			session.close();
		}
	}
	
	@Test
	//查询T+N账户结算详细信息
	public void queryAccountSettleInfoT(){
		SqlSession session = sqlSessionFactory.openSession();
		try{
			AccountSettleInfoBeanMapper mapper = session.getMapper(AccountSettleInfoBeanMapper.class);
			
			AccountSettleInfo info = new AccountSettleInfo();
			info.setMerchantNo("102002858120033");
			info.setId(16381925);
			AccountSettleInfo settleInfo = mapper.queryAccountSettleInfoT(info);
			System.out.println(settleInfo.getSettleDate());
		} finally {
			session.close();
		}
	}
	
	@Test
	//查询D+0账户结算数
	public void queryAccountSettleInfoDCount(){
		SqlSession session = sqlSessionFactory.openSession();
		try{
			AccountSettleInfoBeanMapper mapper = session.getMapper(AccountSettleInfoBeanMapper.class);
			
			AccountSettleInfo info = new AccountSettleInfo();
			info.setStartDate("2015-02-01");
			info.setEndDate("2015-08-10");
			info.setMerchantNo("Z08000000615755");
			Integer count = mapper.queryAccountSettleInfoDCount(info);
			System.out.println(count);
		} finally {
			session.close();
		}
	}
	
	@Test
	//查询D+0账户结算列表
	public void queryAccountSettleInfoDList(){
		SqlSession session = sqlSessionFactory.openSession();
		try{
			AccountSettleInfoBeanMapper mapper = session.getMapper(AccountSettleInfoBeanMapper.class);
			
			AccountSettleInfo info = new AccountSettleInfo();
			info.setStartDate("2015-02-01");
			info.setEndDate("2015-08-10");
			info.setMerchantNo("Z08000000615755");
			info.setPage(2);
			info.setRows(5);
			Integer count = mapper.queryAccountSettleInfoDCount(info);
			if(count > 0){
				info.getPager().setRowCount(count);
				List<AccountSettleInfo> list= mapper.queryAccountSettleInfoDList(info);
				for(AccountSettleInfo temp : list){
					System.out.println(temp.getSettleMoney());
				}
			}
		} finally {
			session.close();
		}
	}
	
	@Test
	//查询D+0账户结算详细信息
	public void queryAccountSettleInfoD(){
		SqlSession session = sqlSessionFactory.openSession();
		try{
			AccountSettleInfoBeanMapper mapper = session.getMapper(AccountSettleInfoBeanMapper.class);
			
			AccountSettleInfo info = new AccountSettleInfo();
			info.setMerchantNo("Z08000000615755");
			info.setId(79001176);
			AccountSettleInfo settleInfo = mapper.queryAccountSettleInfoD(info);
			System.out.println(settleInfo.getSettleDate());
		} finally {
			session.close();
		}
	}
}
